﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Entity = SeriesTheque.Data;

namespace SeriesTheque.DataService
{
    public static class Translator
    {
        public static User Translate_UserEntity_To_User(Entity.User user)
        {
            User _user = new User();
            _user.User_Id = user.User_Id;
            _user.User_Login = user.User_Login;
            _user.User_Passwrd = user.User_Passwrd;
            _user.User_Enable = user.User_Enable;
            _user.User_date = user.User_date;

            List<Serie> listSeries = new List<Serie>();
            if (user.Series != null && user.Series.Count() > 0)
            {
                foreach (Entity.Serie serie in user.Series)
                {
                    listSeries.Add(Translator.Translate_SerieEntity_To_Serie(serie));
                }
            }
            else 
            {
                listSeries = null;
            }
            _user.Series = listSeries;

            return _user;
        }

        public static Serie Translate_SerieEntity_To_Serie(Entity.Serie serie)
        {
            Serie _serie = new Serie();

            _serie.Serie_Id = serie.Serie_Id;
            _serie.Serie_name = serie.Serie_name;
            _serie.Serie_Enable = serie.Serie_Enable;
            _serie.Serie_Date = serie.Serie_Date;
            _serie.User_Login = serie.User.User_Login;

            List<Season> listSeasons = new List<Season>();
            if (serie.Seasons != null && serie.Seasons.Count() > 0)
            {
                foreach (Entity.Season season in serie.Seasons)
                {
                    listSeasons.Add(Translator.Translate_SeasonEntity_To_Season(season));
                }
            }
            else 
            {
                listSeasons = null;
            }
            _serie.Seasons = listSeasons;

            return _serie;
        }

        public static Season Translate_SeasonEntity_To_Season(Entity.Season season)
        {
            Season _Season = new Season();

            _Season.Season_Id = season.Season_Id;
            _Season.Season_Enable = season.Season_Enable;
            _Season.Season_Date = season.Season_Date;
            _Season.Serie_Id = season.Serie.Serie_Id;

            List<Episode> listEpisodes = new List<Episode>();
            if (season.Episodes != null && season.Episodes.Count() > 0)
            {
                foreach (Entity.Episode episode in season.Episodes)
                {
                    listEpisodes.Add(Translator.Translate_EpisodeEntity_To_Episode(episode));
                }
            }
            else
            {
                listEpisodes = null;
            }
            _Season.Episodes = listEpisodes;

            return _Season;
        }

        public static Episode Translate_EpisodeEntity_To_Episode(Entity.Episode episode)
        {
            Episode _Episode = new Episode();

            _Episode.Episode_Id = episode.Episode_Id;
            _Episode.Episode_Number = episode.Episode_Number;
            _Episode.Episode_Enable = episode.Episode_Enable;
            _Episode.Episode_Date = episode.Episode_Date;
            _Episode.Season_Id = episode.Season.Season_Id;

            return _Episode;
        }

        public static List<User> Translate_ListUsersEntity_To_ListUsers(List<Entity.User> users)
        {
            List<User> listUsers = new List<User>();
            if (users != null && users.Count() > 0)
            {
                foreach (Entity.User user in users)
                {
                    listUsers.Add(Translator.Translate_UserEntity_To_User(user));
                }

                return listUsers;
            }
            else
            {
                return null;
            }
        }
        
        public static List<Serie> Translate_ListSeriesEntity_To_ListSeries(List<Entity.Serie> series)
        {
            List<Serie> listSeries = new List<Serie>();
            
            if (series != null && series.Count() > 0)
            {
               
                foreach (Entity.Serie serie in series)
                {
                    listSeries.Add(Translator.Translate_SerieEntity_To_Serie(serie));
                }

                return listSeries;
            }
            else
            {
                return null;
            }
        }
        
        public static List<Episode> Translate_ListEpisodesEntity_To_ListEpisodes(List<Entity.Episode> episodes)
        {
            List<Episode> listEpisodes = new List<Episode>();
            if (episodes != null && episodes.Count() > 0)
            {
                foreach (Entity.Episode episode in episodes)
                {
                    listEpisodes.Add(Translator.Translate_EpisodeEntity_To_Episode(episode));
                }
				return listEpisodes;
			}
			else
			{
				return null;
			}
		}

        public static List<Season> Translate_ListSeasonsEntity_To_ListSeasons(List<Entity.Season> seasons)
        {
            List<Season> listSeasons = new List<Season>();
            if (seasons != null && seasons.Count() > 0)
            {
                foreach (Entity.Season season in seasons)
                {
                    listSeasons.Add(Translator.Translate_SeasonEntity_To_Season(season));
                }

                return listSeasons;
            }
            else
            {
                return null;
            }
        }

        

    }
}
